﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace QunYing.Common
{
   public class ClientProxyFactory
    {
       public static T GetProxy<T>(string serviceAddr)
       {
           NetTcpBinding bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.Security.Mode = SecurityMode.None;
           bind.ReceiveTimeout = TimeSpan.MaxValue;
           bind.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
           return ChannelFactory<T>.CreateChannel(bind, new EndpointAddress(GlobalInfo.ServiceBaseAddr + serviceAddr));
       }

       public static void Close(object objec)
       {
           ICommunicationObject obj = objec as ICommunicationObject;
           if (obj != null)
               obj.Close();
       }
    }
}
